package com.robot.api.dao;

import java.sql.Array;
import java.util.Map;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor;


public abstract class AbstractBizBaseDao<K, V> extends AbstractBaseDao {
	

	protected DataSource dataSource;

	protected NamedParameterJdbcTemplate namedJdbcTemplate;

	protected JdbcTemplate jdbcTemplate;

	protected SimpleJdbcInsert insertActor;
	
	protected SimpleJdbcCall jdbcCallActor;

	public DataSource getDataSource() {
		return this.dataSource;
	}

	@Resource(name="dataSource")
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
		this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
		this.jdbcTemplate = new JdbcTemplate(dataSource);
		this.jdbcTemplate.setNativeJdbcExtractor(new C3P0NativeJdbcExtractor());
		this.jdbcCallActor = new SimpleJdbcCall(jdbcTemplate);
	}
	
	public String getValue(Map<String, Object> resutlMap, String key) {
		String value = "";
		if (resutlMap != null) {
			value = resutlMap.get(key) + "";
		}

		return value;
	}

	public Array getValue4Array(Map<String, Object> resutlMap, String key) {
		Array value = null;
		if (resutlMap != null && resutlMap.get(key) instanceof Array) {
			value = (Array) resutlMap.get(key);
		}

		return value;
	}
}
